package com.office.file.permission.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.office.common.annotation.Log;
import com.office.common.core.controller.BaseController;
import com.office.common.core.domain.AjaxResult;
import com.office.common.enums.BusinessType;
import com.office.file.permission.domain.FilePermission;
import com.office.file.permission.service.IFilePermissionService;
import com.office.common.utils.poi.ExcelUtil;
import com.office.common.core.page.TableDataInfo;

/**
 * 文档权限Controller
 * 
 * @author ruoyi
 * @date 2025-05-23
 */
@RestController
@RequestMapping("/file/permission")
public class FilePermissionController extends BaseController
{
    @Autowired
    private IFilePermissionService filePermissionService;

    /**
     * 查询文档权限列表
     */
    @PreAuthorize("@ss.hasPermi('file:permission:list')")
    @GetMapping("/list")
    public TableDataInfo list(FilePermission filePermission)
    {
        startPage();
        List<FilePermission> list = filePermissionService.selectFilePermissionList(filePermission);
        return getDataTable(list);
    }

    /**
     * 导出文档权限列表
     */
    @PreAuthorize("@ss.hasPermi('file:permission:export')")
    @Log(title = "文档权限", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FilePermission filePermission)
    {
        List<FilePermission> list = filePermissionService.selectFilePermissionList(filePermission);
        ExcelUtil<FilePermission> util = new ExcelUtil<FilePermission>(FilePermission.class);
        util.exportExcel(response, list, "文档权限数据");
    }

    /**
     * 获取文档权限详细信息
     */
    @PreAuthorize("@ss.hasPermi('file:permission:query')")
    @GetMapping(value = "/{permissionId}")
    public AjaxResult getInfo(@PathVariable("permissionId") Long permissionId)
    {
        return success(filePermissionService.selectFilePermissionByPermissionId(permissionId));
    }

    /**
     * 新增文档权限
     */
    @PreAuthorize("@ss.hasPermi('file:permission:add')")
    @Log(title = "文档权限", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FilePermission filePermission)
    {
        return toAjax(filePermissionService.insertFilePermission(filePermission));
    }

    /**
     * 修改文档权限
     */
    @PreAuthorize("@ss.hasPermi('file:permission:edit')")
    @Log(title = "文档权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FilePermission filePermission)
    {
        return toAjax(filePermissionService.updateFilePermission(filePermission));
    }

    /**
     * 删除文档权限
     */
    @PreAuthorize("@ss.hasPermi('file:permission:remove')")
    @Log(title = "文档权限", businessType = BusinessType.DELETE)
	@DeleteMapping("/{permissionIds}")
    public AjaxResult remove(@PathVariable Long[] permissionIds)
    {
        return toAjax(filePermissionService.deleteFilePermissionByPermissionIds(permissionIds));
    }
}
